package com.ggh.jinjilive.ui.mall.shop;


import android.os.Bundle;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.BarUtils;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ActivityMineShopBinding;
import com.ggh.jinjilive.ui.BaseActivity;
import com.ggh.jinjilive.ui.mall.order.OrderActivity;
import com.ggh.jinjilive.ui.mall.order.OrderFragment;
import com.ggh.jinjilive.utils.ARouterUtils;
import com.gyf.immersionbar.ImmersionBar;

import org.jetbrains.annotations.NotNull;

/**
 * 我的店铺
 */
@Route(path = ARouterUtils.MineShopActivity)
public class MineShopActivity extends BaseActivity<ActivityMineShopBinding> {
    //跳转到那个
    public int index = 0;

    private String[] mFragmentTitles = {"待处理", "商品管理","门店中心"};

    //
    private ProfitOrderAdapter profitOrderAdapter;
    @Override
    public void initCreate() {
        super.initCreate();
        ImmersionBar.with(this).init();
    }

    @Override
    public void initParam() {
        super.initParam();
        index = getIntent().getExtras().getInt("index", 0);
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_mine_shop;
    }

    @Override
    public void initView() {
        super.initView();
        setWhiteActionBarStyle("",true,true);
        //获取状态栏高度
        binding.llSpacing.setPadding(0, BarUtils.getStatusBarHeight(),0,0);

        //适配器
        profitOrderAdapter = new ProfitOrderAdapter(getSupportFragmentManager());
        binding.vp.setAdapter(profitOrderAdapter);
        binding.stlOrder.setViewPager(binding.vp, mFragmentTitles);
        binding.vp.setCurrentItem(index);
    }




    class ProfitOrderAdapter extends FragmentPagerAdapter {

        public ProfitOrderAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            if(position == 0){
                return new PendingFragment();
            }else if(position == 1){
                return new CommodityManagementFragment();
            }else {
                return new ShopCentreFragment();
            }

        }

        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public void destroyItem(@NonNull @NotNull ViewGroup container, int position, @NonNull @NotNull Object object) {
//            super.destroyItem(container, position, object);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitles[position];
        }

        @Override
        public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
            super.setPrimaryItem(container, position, object);
        }
    }
}
